<style lang="sass" scoped>
    .mt50 {
        margin-top: 50px;
    }
</style>
<template>
    <div v-jurdie="'book3100'" class="container">
        <div class="search-cont">
            <el-input placeholder="请搜索" v-model.trim="search.keyWord">
                <i slot="prefix" class="el-input__icon el-icon-search"></i>
            </el-input>
            <el-date-picker v-model="dateValue" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" format="yyyyMMdd"
                value-format="yyyy-MM-dd HH:mm:ss">
            </el-date-picker>
            <el-select v-model="search.companyCode" placeholder="请选择分销商">
                <el-option v-for="item in companyList" :key="item.companyCode" :label="item.companyName" :value="item.companyCode">
                </el-option>
            </el-select>
            <el-button @click="getList()" type="primary" :plain="false">搜索</el-button>
            <el-button @click="download()" type="primary" :plain="false">导出</el-button>
        </div>
        <div class="tabs-cont">
            <el-button
                @click="search.status=''" 
                :type="search.status===''?'primary':''">全部</el-button>
            <el-button
                @click="search.status=0" 
                :type="search.status===0?'primary':''">待付款</el-button>
            <el-button
                @click="search.status=1" 
                :type="search.status===1?'primary':''">待发货</el-button>
            <el-button
                @click="search.status=2" 
                :type="search.status===2?'primary':''">已发货</el-button>
            <el-button
                @click="search.status=3" 
                :type="search.status===3?'primary':''">已签收</el-button>
            <el-button
                @click="search.status=4" 
                :type="search.status===4?'primary':''">已完成</el-button>
            <el-button
                @click="search.status=5" 
                :type="search.status===5?'primary':''">已取消</el-button>
            <el-button
                @click="search.status=6" 
                :type="search.status===6?'primary':''">已售后</el-button>
        </div>
        <div class="table-cont">
            <el-table :data="list" style="width: 100%">
                <el-table-column prop="orderNo" label="订单编号">
                </el-table-column>
                <el-table-column prop="companyName" label="分销商">
                </el-table-column>
                <el-table-column prop="goodsTotalFee" label="商品金额">
                </el-table-column>
                <el-table-column prop="carriageFee" label="运费">
                </el-table-column>
                <el-table-column prop="realPayFee" label="订单金额">
                </el-table-column>
                <el-table-column prop="xxx" label="状态">
                    <template slot-scope="props">
                        {{props.row.status | orderStatus}}
                    </template>
                </el-table-column>
                <el-table-column prop="createTime" label="下单时间">
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="props">
                        <el-button v-jurdie="'book3101'" @click="routerGo('order_detail',{orderNo:props.row.orderNo})" type="primary" :plain="false" size="small">详情</el-button>
                        <el-button v-jurdie="'book3102'" v-if="props.row.status===1" @click="logisShow(props.row)" type="primary" :plain="false" size="small">发货</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination background layout="prev, pager, next" :total="search.total" @current-change="handleCurrentChange">
            </el-pagination>
        </div>

        <!-- 发货 -->
        <el-dialog title="发货" :visible.sync="logisObj.show">
            <el-form label-width="80px">
                <el-form-item label="订单编号:">
                    {{logisObj.orderNo}}
                </el-form-item>
                <el-form-item label="快递公司:">
                    <el-select v-model="logisObj.logisticsCompanyCode" placeholder="请选择快递公司">
                        <el-option v-for="item in logisList" :key="item.logisticsCompanyCode" :label="item.logisticsCompany" :value="item.logisticsCompanyCode">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="运单号:">
                    <el-input v-model.trim="logisObj.logisticsNo"></el-input>
                </el-form-item>
                <div class="tc mt20">
                    <el-button @click="modifyLogisticsInfo()" type="primary">发货</el-button>
                </div>
            </el-form>
        </el-dialog>
    </div>
</template>
<script>
    export default {
        components: {
        },
        data() {
            return {
                //列表搜索参数
                search:{
                    keyWord:'', //	是	string	搜索关键字
                    startTime:'', //	是	string	开始时间，格式yyyy-MM-dd hh:mm:ss
                    endTime:'', //	是	string	结束时间，格式yyyy-MM-dd hh:mm:ss
                    status:'', //	是	string	状态，0-未上架，1-已上架
                    categId:'', //	是	string	类目ID
                    companyCode:'',
                    pageNo:1, //	是	string	页码
                    pageSize:config.pageSize, //	是	string	当前页显示的条数
                    total:0,
                },
                list:[],
                dateValue:'',
                logisObj:{
                    show:false,
                    orderNo:'',//	是	string	订单编号
                    logisticsCompanyCode:'',//	是	string	快递公司
                    logisticsNo:'',//	是	string	运单号
                },
                logisList:[],
                companyList:[],
            };
        },
        watch:{
            'dateValue'(val){
                let dates = JSON.parse(JSON.stringify(val));
                Object.assign(this.search,{
                    startTime:dates[0],
                    endTime:dates[1],
                })
            },
            'search.status'(val){
                this.getList();
            }
        },
        created(){
            server.getLogisticsCompanyList().then(res=>{
                this.logisList = res;
            })
            server.getCompanyList().then(res=>{
                this.companyList = res;
            })
        },
        mounted() {
            this.$nextTick(() => {
                this.getList();
            });
        },
        methods: {
            handleCurrentChange(val) {
                this.search.pageNo = val;
                this.getList();
            },
            getList() {
                let param = JSON.parse(JSON.stringify(this.search));
                util.ajax({
                    url: config.baseApi + "bookMall-admin/api/order/getOrderListPage",
                    data: param,
                    success: data => {
                        this.list = data.data.record;
                        this.search.total = data.data.totalNum;
                    }
                });
            },
            logisShow(item){
                this.logisObj={
                    show:true,
                    orderNo:item.orderNo,//	是	string	订单编号
                    logisticsCompanyCode:'',//	是	string	快递公司
                    logisticsNo:'',//	是	string	运单号
                }
            },
            //去发货
            modifyLogisticsInfo(){
                let param = JSON.parse(JSON.stringify(this.logisObj));
                util.ajax({
                    url:config.baseApi + 'bookMall-admin/api/order/modifyLogisticsInfo',
                    data:param,
                    success:(data=>{
                        popup.miss({content:'发货成功！'});
                        this.logisObj.show = false;
                        this.getList();
                    })
                })
            },
            download(){
                let url = util.serialize(config.baseApi+'bookMall-admin/api/order/exportOrder',{
                    keyWord:this.search.keyWord,
                    startTime:this.search.startTime,
                    endTime:this.search.endTime,
                    status:this.search.status,
                })
                util.interIosForIframe(false,url)
            }
        },
        
    };
</script>